//
//  HelpViewController.m
//  bitcoin
//
//  Created by caiyajun on 2018/5/9.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "HelpViewController.h"
#import "HelpFrame.h"
#import "HelpCell.h"
#import "HelpOutModel.h"
#import "HelpModel.h"
@interface HelpViewController ()<HelpCellDelegate>
@property (nonatomic,strong) NSMutableDictionary *linkman1Dic;
@property (nonatomic,strong) NSMutableArray *dataArr;
@property (nonatomic,strong) NSMutableArray *frameArray;

@property (nonatomic,strong) NSArray *dataArray;
@property (nonatomic,strong) NSArray *contentArray;
@end

@implementation HelpViewController
-(NSMutableDictionary *)linkman1Dic{
    if(_linkman1Dic == nil){
        _linkman1Dic = [NSMutableDictionary dictionary];
    }
    return _linkman1Dic;
}
- (NSMutableArray *)dataArr {
    if (_dataArr == nil) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}
- (NSMutableArray *)frameArray {
    if (_frameArray == nil) {
        _frameArray = [NSMutableArray array];
    }
    return _frameArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self requstData];
//    [self.linkman1Dic setValue:@"sdsa" forKey:@"title"];
//    [self.linkman1Dic setValue:@"1" forKey:@"selectRow"];
//    [self.linkman1Dic setValue:@"NO" forKey:@"isSelect"];
//    [self.linkman1Dic setValue:@"来自于加拿大多伦多的Skrumble Network（SKM）旨在搭建一个真正安全的通讯网络，打造全球通讯行业公链和点对点社交区块链社区。目前Skrumble Network已获得20余家全球顶级机构的战略投资；" forKey:@"content"];
//    HelpModel *helpModel = [HelpModel mj_objectWithKeyValues:self.linkman1Dic];
//    [self.dataArr addObject:helpModel];
//    [self.dataArr addObject:helpModel];
//    [self.dataArr addObject:helpModel];
//    [self.dataArr addObject:helpModel];
//    [self.dataArr addObject:helpModel];
//
//    for (HelpModel *helpModel in self.dataArr) {
//        HelpFrame *frame  = [[HelpFrame alloc] init];
//        frame.helpModel = helpModel;
//        [self.frameArray  addObject:frame];
//    }
    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrowleft-icon"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction:)];
    self.navigationItem.leftBarButtonItem = back;
}
- (void)backAction:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}




- (void)requstData{
    
    [LSRequestManager getRequestWithURL:HUOBI(@"api/pub/getAssist")
                                 params:nil
                                success:^(NSDictionary *responseData) {
                                    if ([responseData[@"ret"] integerValue ] == 0) {
                                        self.dataArray = [HelpOutModel mj_objectArrayWithKeyValuesArray:responseData[@"data"]];
                                        [self.frameArray removeAllObjects];
                                        if (self.dataArray.count!=0) {
                                            for (HelpOutModel *helpOutModel in self.dataArray) {
//                                                self.contentArray=[HelpOutModel mj_objectArrayWithKeyValuesArray:helpOutModel.item];
                                                [self.dataArr  addObjectsFromArray:helpOutModel.item];
                                            }
                                            for (HelpModel *helpModel in self.dataArr) {
                                                HelpFrame *frame  = [[HelpFrame alloc] init];
                                                frame.helpModel = helpModel;
                                                [self.frameArray  addObject:frame];
                                            }
                                        }
                                        
                                        [self.tableView reloadData];
                                        
                                    
                                        
                                        
                                        
                                        
                                    } else {
                                        [MBProgressHUD showError:responseData[@"msg"]];
                                    }
                                }
                                failure:^(NSError *error) {
                                    
                                }
                                showHUD:NO];
    
    
    
    
    
    
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.frameArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HelpCell *cell = [HelpCell cellWithTable:tableView];
    cell.delegate = self;
    cell.helpFrame = self.frameArray[indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HelpFrame *helpFrame = self.frameArray[indexPath.row];
    return helpFrame.cellHeight;
}
- (void)showAllContentsWithCell:(HelpCell *)helpCell{
    [self.tableView  reloadData];
}
@end
